(defun compress (x)
  (if (consp x) 
      (compr (car x) 1 (cdr x))
      x))

(defun compr (elt n lst)
  (if (null lst)
      (list (n-elts elt n))
      (let ((next (car lst)))
        (if (eql next elt)
            (compr elt (+ n 1) (cdr lst))
            (cons (n-elts elt n)
                  (compr next 1 (cdr lst)))))))

(defun n-elts (elt n)
  (if (> n 1)
      (list n elt)
      elt))

(compress '(0 1 1 1 0 0 0 1 0 1 1 0 0 0))

(nth 0 '(a b c))

(nth 2 '(a b c))

(nthcdr 2 '(a b c))

(defun list-of (n elt)
  (if (zerop n)
      nil
      (cons elt (list-of (- n 1) elt))))

(list-of 10 '(a b c))

(mapcar #'(lambda (x) (+ x 10))
	'(1 2 3))

(mapcar #'list 
	'(1 2 3)
	'(a b c))

(defun our-copy-tree (tr)
  (if (atom tr)
      tr
      (cons (our-copy-tree (car tr))
	    (our-copy-tree (cdr tr)))))

(our-copy-tree '(1 2))

(setq x 4)

(and (integerp x) (zerop (mod x 2)))

(setq x 5)
(substitute 'y 'x '(and (integerp x) (zerop (mod x 2))))

(subst 'y 'x '(and (integerp x) (zerop (mod x 2))))

(defun len (lst)
  (if (null lst)
      0
      (+ (len (cdr lst)) 1)))

(len '(a b c d e f 1 2 3 5))

(member 'b '(a b c))

(member '(a) '((a) (z)) :test #'equal)

(car '(a b c))

(oddp '(2 3 4))

(oddp 1)

(defun our-member-if (fn lst)
  (and (consp lst)
       (if (funcall fn (car lst))
	   lst
	   (our-member-if fn (cdr lst)))))

(length '(a b c))

(subseq '(a b c d) 1 2)

(subseq '(a b c d) 1)

(reverse '(a b c))

(defun mirror? (s)
  (let ((len (length s)))
    (and (evenp len)
	 (let ((mid (/ len 2)))
	   (equal (subseq s 0 mid)
		  (reverse (subseq s mid)))))))

(mirror? '(a b b a))

(mirror? '(a a b a))

(sort '(0 2 1 3 8) #'<)

(nth 1 '(a b c))

(defun nthmost (n lst)
  (nth (- n 1)
       (sort (copy-list lst) #'>)))

(nthmost 2 '(0 2 1 3 8))

(every #'oddp '(1 3 5))

(some #'oddp '(2 6 4))

(push obj lst)

(setf x '(b))

(push 'a x)

(pop x)

(defun our-reverse (lst)
  (let ((acc nil))
    (dolist (elt lst)
      (push elt acc))
    acc))

(setf trans '((+ . "add") (- . "subtract")))

'(a b (c d))
'(a (b (c (d))))
'(a (b . c) . d)

(defun new-nuion (lst1 lst2)
  (or (consp lst2)))

(setf arr (make-array '(2 3) :initial-element nil))

(aref arr 0 0)

(vector "a" 'b 3)

(sort)

(aref "abc" 1)

(char "abc" 2)

point

(defstruct point
  x
  y)

(setf p (make-point :x 0 :y 1))

(point-x p)

(defstruct polemic
  (type (progn 
	  (format t "What kind of polemic was it ?")
	  (read)))
  (effect nil))

(make-polemic)

(setf ht (make-hash-table))

(gethash 'color ht)

(dolist (x '(a b c d e f))
  (format t "~A " x)
  (if (eql x 'c)
      (return 'done)))

(format t "~A " '(a b c d))

(tagbody
   (setf x 0)
   top
   (setf x (+ x 1))
   (format t "~A " x)
   (if (< x 10) (go top)))

(defun show-squares (start end)
  (do ((i start (+ i 1)))
      ((> i end) 'done)
    (format t "~A ~A~%" i (* i i))))

(show-squares 1 10)

(let ((x (car y)))
  (cons x x))

(defun mystery (x y)
  (if (null y)
      nil
      (if (eql (car y) x)
	  0
	  (let ((z (mystery x (cdr y))))
	    (and z (+ z 1))))))

(mystery 'a '(b b b b b b b b b a))

(defun mystery (x y)
  (cond ((null y) nil)
	((eql (car y) x) 0)
	(t (let ((z (mystery x (cdr y))))
	    (and z (+ z 1))))))

(mystery 'a '(b b b b b b b b b a))

(defun my-square (x)
  (cond ((null x) nil)
	((< (car x) 5) 'done)
	(t (dolist (elt x)
	     (format t "~A~%" (* elt elt))))))

(my-square '(10 13 14 15 1 3 8))

(defun philosoph (thing &optional property)
  (list thing 'is property))

(philosoph 'death 'a)

single?

(single? '(a))

(defun combiner (x)
  (typecase x
    (number #'+)
    (list #'append)
    (t #'list)))

(defun combine (&rest args)
  (apply (combiner (car args))
	 args))

(combine 'a 'b 'c)

(concatenate 'string "a" "c")

(defun test()
  "this is test function!"
  (format t "hello world"))

(test)

(defmacro n-of (to from)
  )

(defun foo(x)
  (if (zerop x)
      0
      (+ 1 (foo (1- x)))))

(time (foo 100000))

(defun foo (x)
  (labels ((foo-t-r (x acc)
             (if (zerop x)
                 acc 
                 (foo-t-r (1- x) (1+ acc)))))
    (foo-t-r x 0)))

(dotimes (x 10)
  (format t "~d " x))

(let ((x 10)
       (y (+ x 10)))
  (list x y))

(vector 1 2 3)

(let ((in (open "/data/my-code/study/print_test.txt") :if-does-exist nil))
  (when in
    (format t "~a~%" (read-line in))
    (close in)))

(print-file)

(send)


(step (if (oddp 5) 'yes 'no))

(random 5.0)

(documentation 'cons)

(documentation 'list 'function)

(defun half (n) (* n 0.5))

(defun average (x y)
  (+ (half x) (half y)))

(trace half average)

(average 3 7)

(trace)

(untrace average)

(trace halt)

(dtrace halt)

(untrace half)

(dtrace)


(defun fact(n)
  "阶乘，eg. n! = n(n-1)..1 不错，哈哈"
  (if (zerop n) ;;判断n是否等于零
      1
      (* n (fact (1- n)))))

(trace fact)

(fact 5)

(dolist (x '(red blue green) 'flowers)
  (format t "~&Rose are ~S." x))

(documentation 'fact 'function)


(defun make-adder (n)
  #'(lambda (x) (+ x n)))

(setq add2 (make-adder 2)
      add10 (make-adder 10))

(funcall add2 5)

(funcall add10 5)

(in-package cl-user)

(defun our-length (lst)
  (if (null lst)
      0
      (1+ (our-length (cdr lst)))))

(our-length '(1 2 3 4))

(trace our-length)

(defun our-length (lst)
  (labels ((my-len (lst acc)
		(if (null lst)
		    acc
		    (my-len (cdr lst) (1+ acc)))))
    (my-len lst 0)))

(defun ok (x)
  (nconc (list 'a x) (list 'c)))

(ok '(a b))

(defun not-ok (x)
  (nconc (list 'a) x (list 'c)))

(not-ok '(a b))

(defstruct node contents yes no)
(defvar *nodes* (make-hash-table))
(defun defnode (name conts &optional yes no)
  (setf (gethash name *nodes*)
	(make-node :contents conts
		   :yes yes
		   :no no)))
(defnode 'people "Is the person a man?"
  'male 'female)

(let ((a 1))
  (psetq a 2 b a)
  (list a b))

(defun our-every (fn lst)
  (if (null lst)
      t
      (and (funcall fn (car lst))
	   (our-every fn (cdr lst)))))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(defvar *checks* (make-array 100 :adjustable t :fill-pointer 0)
  "A vector of checks.")

(defconstant +first-check-number+ 100
  "The number of the first check.")

(defvar *next-check-number* +first-check-number+
  "The number of the next check.")

(defvar *payees* (make-hash-table :test #'equal)
  "Payees with checks paid to each.")

(defstruct check number date amount payee memo)

(defun current-date-string ()
  "Return current date as a string."
  (multiple-value-bind (sec min hr day mon yr dow dst-p tz)
      (get-decoded-time)
    (declare (ignore sec min hr dow dst-p tz))
    (format nil "~A-~A-~A" yr mon day)))

(defstruct foo-struct a b c)

(let ((foo-1 (make-foo-struct :a 1 :b "two")))
  (print (foo-struct-b foo-1))
  (print (foo-struct-c foo-1))
  (values))


(print *from_dir*)

(auto-make-java)

(maphash #'(lambda (k1 v1)
			(format t "~A => ~A~%" k1 v1)) v)

(maphash #'(lambda (k v) 
		 (format t "~A => ~A ~%" k v)) tables)

(auto-make-java "/data/workspace/cblink4/" "/data/workspace/cblink6/")

(extract-field "asdadf name=\"adsfadf\" type=\"java.lang.String\"" "type")

(sub-field-type "java.lang.String")

(is-find "adfadf" "fa")

;;"/data/workspace/cblink4/src/com/cblink/persistent/model/*.xml"
(multiple-value-bind (table-name id fields)
    (find-table-name "/data/workspace/cblink4/src/com/cblink/persistent/model/*.xml")
  (print table-name))

(let ((tables (find-table-name "/data/workspace/cblink4/src/com/cblink/persistent/model/*.xml")))
  (maphash #'(lambda (k v) (format t "~a => ~a~%" k v)) tables))


(subseq "abcd" 1 4)

(assos "c" "abcd")

(position #\c "abcd")
1
(position #\t\s "abasdfadftsf" :test #'equal)

(search "dfa" "asdfasdfasabcddfasdf")

(file-namestring #p"/foo/bar/baz.txt")

(cl-ppcre:all-matches-as-strings "[a-zA-Z]{3,}" text)

(multiple-value-bind (a b)
    (cl-ppcre:scan-to-strings "name=\"(.*?)\"" "adfad adsf name=\"aaaa.adf\"" )
  (list a b)
  (elt b 0))

(defun find-table1 (path)
  (let ((files (directory path)))
    (dolist (file files)
      (let ((filename (file-namestring file)))
	(print filename)))))

(defun find-table2 (path)
  (print "aaa"))



(with-open-file (stream "/tmp/test.txt" :direction :output)
  (write-line "adfadf" stream))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;信用卡分期利率计算
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun yueli (nianli)
  (/ (* 1.1 nianli) 12))

(defun yueli-n (R N)
  (if (eq N 1)
      (1+ R)
      (* (1+ R) (yueli-n R (1- N)))))

(defun fenqi (P R N)
  (let ((r-n (yueli-n R N)))
    (* P (/ (* R r-n) (- r-n 1)))))

(defun fenqi-yueli (P R N B)
  (if (> B (fenqi P R N))
      (if (< B (fenqi P (- R 0.00001) N))
	  (- R 0.00001))
      ()))

(defun fenqi-yueli1 (P R N B)
  (when (> B (fenqi P R N))
    (format t "利率：~A 每月还款~A~%" R (fenqi P R N))
    (setf R (+ R 0.00001))))

(defun fenqi-yueli (P R N B)
  (do* ((R+ R (+ 0.00001 R+))
	(benjin (fenqi P R N)))
      ((> benjin B))
    (setf benjin (fenqi P R+ N))
    (format t "~A ~A~%" R+ benjin)))

(defun fenqi-yueli (P R (N B)
  (loop
       (setq benjin (fenqi P R N))
     ))

(do ((x 1 (+ x 1))
       (y 1 (* y 2)))
      ((> x 5) y)
    (print y)
    (print 'worqking))

(fenqi-yueli 69500 0.00646 48 2067.09)
(fenqi-yueli 69500 0.00646 48 2067.09)
(fenqi-yueli 10000 0.00646 12 (/ (+ 10000 (* 10000 0.072)) 12))
(fenqi-yueli 10000 0.00646 12 (+ (/ 10000 12) (* 10000 0.0068)))
(fenqi-yueli 10000 0.00646 48 (+ (/ 10000 48) (* 10000 0.0066)))

(/ (+ 10000 (* 10000 0.072)) 12)
(yueli 0.0705)
0.00646
(yueli-n (yueli 0.0705) 12)
(fenqi 220000 (yueli 0.0705) (* 15 12))
(fenqi 69500 (/ 0.089 12) (* 12 4))
(fenqi 10000 0.00646 12)
(+ (fenqi 69500 (/ 0.089 12) (* 12 4)) (* 69500 0.0049))

(/ 340.55 69500)
(+ 1726.54 340.55)
2067.09
(* 0.0155897075 12)


0.015
0.1956

zada
0.01558
0.18696

zaohang
7.2%
0.01086
0.13032

jiaotong
0.68%
0.01227
0.14724

mingsheng
0.6%
0.01086
0.13032

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


